﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<MVCBugTracker.ViewModels.BugEditViewModel>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Edit
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="HeadContent" runat="server">
    <script type="text/javascript">
        function ClearCommentText() {
            $('#comment').val("");
        }
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h2>
        Bug:
        <%: Model.Bug.BugID %></h2>
    <% using (Html.BeginForm())
       {%>
    <%: Html.ValidationSummary(true) %>
    <div id="actionbuttons" style="width: 800px; text-align: right;">
        <p>
            <input type="submit" name="button" value="Save" />
            <%: Html.ActionLink("Delete", "Delete", new { id = Model.Bug.BugID }, new { @class = "button" }) %>
            <%: Html.ActionLink("Cancel", "Index", new { projectid = Model.Bug.ProjectID }, new { @class = "button" }) %>
        </p>
    </div>
    <hr />
    <div class="editor-label" style="float: left; width: 150px">
        <%: Html.LabelFor(model => model.Bug.Title)%>:
    </div>
    <div class="editor-field" style="float: left;">
        <%: Html.TextBoxFor(model => model.Bug.Title, new { style = "width:650px" })%>
        <%: Html.ValidationMessageFor(model => model.Bug.Title)%>
    </div>
    <div class="clear">
    </div>
    <div class="editor-label" style="float: left; width: 150px">
        <%: Html.LabelFor(model => model.Bug.CategoryID)%>:
    </div>
    <div class="editor-field" style="float: left;">
        <%: Html.DropDownListFor(model => model.Bug.CategoryID, new SelectList(Model.ProjectCategories, "CategoryID", "Name", Model.Bug.CategoryID), new { style = "width:200px" })%>
    </div>
    <div class="clear">
    </div>
    <div class="editor-label" style="float: left; width: 150px">
        <%: Html.LabelFor(model => model.Bug.LastUpdate)%>:
    </div>
    <div class="editor-field" style="float: left;">
        <%: String.Format("{0:g}", Model.Bug.LastUpdate)%>
    </div>
    <div class="clear">
    </div>
    <hr />
    <div style="float: left; width: 430px">
        <div class="editor-label" style="float: left; width: 150px">
            <%: Html.LabelFor(model => model.Bug.AssignedUserName)%>:
        </div>
        <div class="editor-field" style="float: left;">
            <%: Html.DropDownListFor(model => model.Bug.AssignedUserName, new SelectList(Model.ProjectMembers, "UserName", "UserName", Model.Bug.AssignedUserName), new { style = "width:200px" })%>
        </div>
        <div class="clear">
        </div>
        <div class="editor-label" style="float: left; width: 150px">
            <%: Html.LabelFor(model => model.Bug.CreatorUserName)%>:
        </div>
        <div class="editor-field" style="float: left;">
            <%: Model.Bug.CreatorUserName%>
        </div>
        <div class="clear">
        </div>
        <div class="editor-label" style="float: left; width: 150px">
            <%: Html.LabelFor(model => model.Bug.DateCreated)%>:
        </div>
        <div class="editor-field" style="float: left;">
            <%: String.Format("{0:g}", Model.Bug.DateCreated)%>
        </div>
        <div class="clear">
        </div>
        <div class="editor-label" style="float: left; width: 150px">
            Project:
        </div>
        <div class="editor-field" style="float: left;">
            <%: Model.ProjectName%>
        </div>
        <div class="clear">
        </div>
    </div>
    <div style="float: left">
        <div class="editor-label" style="float: left; width: 150px">
            <%: Html.LabelFor(model => model.Bug.StatusID)%>:
        </div>
        <div class="editor-field" style="float: left;">
            <%: Html.DropDownListFor(model => model.Bug.StatusID, new SelectList(Model.ProjectStatuses, "StatusID", "Name", Model.Bug.StatusID), new { style = "width:200px" })%>
            <% if (Model.Bug.StatusID != null)
               { %>
            <img id="statusurl" src="<%: ResolveUrl(Model.ProjectStatuses.SingleOrDefault(s => s.StatusID == Model.Bug.StatusID).ImageUrl) %>"
                alt="" />
            <%} %>
        </div>
        <div class="clear">
        </div>
        <div class="editor-label" style="float: left; width: 150px">
            <%: Html.LabelFor(model => model.Bug.PriorityID)%>:
        </div>
        <div class="editor-field" style="float: left;">
            <%: Html.DropDownListFor(model => model.Bug.PriorityID, new SelectList(Model.ProjectPriorities, "PriorityID", "Name", Model.Bug.PriorityID), new { style = "width:200px" })%>
            <% if (Model.Bug.PriorityID != null)
               { %>
            <img id="priorityurl" src="<%: ResolveUrl(Model.ProjectPriorities.SingleOrDefault(p => p.PriorityID == Model.Bug.PriorityID).ImageUrl) %>"
                alt="" />
            <% } %>
        </div>
        <div class="clear">
        </div>
        <div class="editor-label" style="float: left; width: 150px">
            <%: Html.LabelFor(model => model.Bug.MilestoneID)%>:
        </div>
        <div class="editor-field" style="float: left;">
            <%: Html.DropDownListFor(model => model.Bug.MilestoneID, new SelectList(Model.ProjectMilestones, "MilestoneID", "Name", Model.Bug.MilestoneID), new { style = "width:200px" })%>
            <% if (Model.Bug.MilestoneID != null)
               { %>
            <img id="milestoneurl" src="<%: ResolveUrl(Model.ProjectMilestones.SingleOrDefault(m => m.MilestoneID == Model.Bug.MilestoneID).ImageUrl) %>"
                alt="" />
            <% } %>
        </div>
        <div class="clear">
        </div>
        <%if(Model.Bug.ParentBug != null)
          { %>
        <div class="editor-label" style="float: left; width: 150px">
            Parent bug:
        </div>
        <div class="editor-field" style="float: left;">
            #<%:Html.ActionLink(Model.Bug.ParentBugID.ToString(), "Edit", new
{
    id = Model.Bug.ParentBugID
})%>: <%:Model.Bug.ParentBug.Title %>
        </div> 
        <div class="clear">
        </div>
        <%} %>
        
    </div>
    <div class="clear">
    </div>
    <br />
    <div class="tab-container">
        <div id="tabs">
            <ul>
                <li><a href="#tabs-1">Description</a></li>
                <li><a href="#tabs-2">Comments</a></li>
                <li><a href="#tabs-3">Attachments</a></li>
                <li><a href="#tabs-4">History</a></li>
                <li><a href="#tabs-5">Notification</a></li>
                <li><a href="#related">Related bugs</a></li>
            </ul>
            <div id="tabs-1">
                <%: Html.TextAreaFor(model => model.Bug.Description, 15, 105, null)%>
            </div>
            <% } %>
            <div id="tabs-2">
                <% Html.RenderPartial("BugComments", Model.BugCommentViewModel); %>
                <% using (Ajax.BeginForm("AddComment", "Bug", new { id = Model.Bug.BugID }, new AjaxOptions { UpdateTargetId = "comments", OnFailure = "handleFailure", OnSuccess = "ClearCommentText" }))
                   { %>
                <b>
                    <label for="name">
                        Comment</label></b><br />
                <%: Html.TextArea("comment", "", 5, 80, null)%><br />
                <br />
                <input type="submit" value="Submit" />
                <% } %>
            </div>
            <div id="tabs-3">
                <% Html.RenderPartial("BugAttachments", Model.BugAttachmentViewModel); %>
            </div>
            <div id="tabs-4">
                <% Html.RenderPartial("BugHistory", Model.BugHistoryViewModel); %>
            </div>
            <div id="tabs-5">
                <% Html.RenderPartial("BugNotifications", Model.BugNotificationViewModel); %>
            </div>
            <div id="related">
                <% Html.RenderPartial("BugRelated", Model.Bug); %>
            </div>
        </div>
    </div>
    <br />
    <script type="text/javascript">
        $(function () {
            $("#tabs").tabs();

            tinyMCE.init({
                // General options
                mode: "exact",
                elements: "Bug.Description",
                theme: "advanced",
                skin: "o2k7",
                theme_advanced_toolbar_location: "top",
                theme_advanced_toolbar_align: "left",
                theme_advanced_statusbar_location: "bottom",
                theme_advanced_resizing: true,
            });

        });

        $('#Bug_MilestoneID').change(function () {
            var url = '/Project/GetMilestoneURL/' + $("#Bug_MilestoneID").val();
            $.ajax({
                type: 'POST',
                url: url,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    $('#milestoneurl').attr("src", response);
                }
            });
        });

        $('#Bug_PriorityID').change(function () {
            var url = '/Project/GetPriorityURL/' + $("#Bug_PriorityID").val();
            $.ajax({
                type: 'POST',
                url: url,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    $('#priorityurl').attr("src", response);
                }
            });
        });

        $('#Bug_StatusID').change(function () {
            var url = '/Project/GetStatusURL/' + $("#Bug_StatusID").val();
            $.ajax({
                type: 'POST',
                url: url,
                contentType: 'application/json; charset=utf-8',
                dataType: 'json',
                success: function (response) {
                    $('#statusurl').attr("src", response);
                }
            });
        });
    </script>
</asp:Content>
